<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <li v-for="item in arr" :key="item.id">{{item.name}}-{{item.age}}</li>
      </ul>
      <ul>
        <li v-for="item in newArr" :key="item.id">
          {{item.name}}-{{item.age}}
        </li>
      </ul>
    </div>
    <script type="module">
      import { createApp, ref, reactive, computed } from "./vue.esm-browser.js";
      const app = createApp({
        setup() {
          const arr = ref([
            { id: 1, name: "jack", age: 20 },
            { id: 2, name: "lili", age: 21 },
            { id: 3, name: "tom", age: 19 },
            { id: 4, name: "lucy", age: 18 },
          ]);
          const newArr = computed(() => {
            return [...arr.value].sort((a, b) => a.age - b.age);
            // return [...arr.value].reverse();
          });
          return {
            arr,
            newArr,
          };
        },
      });
      app.mount("#app"); //挂载
    </script>
  </body>
</html>
